package zj.xinxin.web.controller.article;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zj.xinxin.api.moudle.article.api.TagService;
import zj.xinxin.api.moudle.article.dto.DiscussDto;
import zj.xinxin.api.moudle.article.dto.TagDto;
import zj.xinxin.api.moudle.article.vo.DiscussVo;
import zj.xinxin.api.moudle.article.vo.TagPageSearchVo;
import zj.xinxin.api.moudle.article.vo.TagVo;
import zj.xinxin.common.result.PageResult;
import zj.xinxin.common.result.ResponseResult;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 标签  前端控制器
 * </p>
 *
 * @author zhoujun
 * @since 2022-04-12
 */
@RestController
@Api(tags = "文章标签")
@RequestMapping("/article/tag")
public class TagController {

    @Autowired
    TagService tagService;

    @PostMapping("/add")
    @ApiOperation(value = "添加标签信息")
    public ResponseResult<Boolean> add(@RequestBody @Valid TagVo tag) {

        return tagService.addByVo(tag) ?
                ResponseResult.success("添加成功", true ):
                ResponseResult.fail("保存失败", false);
    }

    @GetMapping("/get/{articleId}")
    @ApiOperation(value = "获取文章的标签信息")
    public ResponseResult<List<TagDto>> get(@PathVariable("articleId") Long articleId) {
        return ResponseResult.success("获取成功", tagService.getByArticleId(articleId));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除标签信息")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        return tagService.removeById(id) ?
                ResponseResult.success("删除成功", true ):
                ResponseResult.fail("删除失败", false);
    }

    @GetMapping("/get")
    @ApiOperation(value = "获取所有标签信息")
    public ResponseResult<PageResult<TagDto>> list(@Valid TagPageSearchVo search){
        return ResponseResult.success("获取成功！", tagService.page(search));
    }
}

